home *** CD-ROM | disk | FTP | other *** search
- /*
- api/update.js
-
- Copyright © 2005, 2006, 2007 Against Intuition, Inc. <info@mywot.com>
- */
-
- var wot_api_update =
- {
- init: function()
- {
- },
-
- send: function()
- {
- try {
- if (WOT_VERSION == wot_prefs.last_version &&
- Date.now() - Number(wot_prefs.update_checked) <
- WOT_INTERVAL_UPDATE_CHECK) {
- return;
- }
-
- /* Increase the last check time a notch */
- wot_prefs.setChar("last_version", WOT_VERSION);
- wot_prefs.setChar("update_checked",
- (Date.now() - WOT_INTERVAL_UPDATE_CHECK +
- WOT_INTERVAL_UPDATE_ERROR).toString());
-
- /* Build a request */
- var request = new XMLHttpRequest();
-
- request.open("GET", WOT_SERVICE_NORMAL +
- WOT_SERVICE_API_UPDATE +
- "?id=" + wot_prefs.witness_id +
- "&nonce=" + wot_crypto.nonce() +
- "&lang=" + wot_util.getstring("language") +
- "&version=" + WOT_PLATFORM + "-" + WOT_VERSION);
-
- new wot_cookie_remover(request);
-
- request.onload = this.onload;
- request.send(null);
- } catch (e) {
- dump("wot_api_update.send: failed with " + e + "\n");
- }
- },
-
- onload: function(event)
- {
- try {
- if (!event || !event.target || event.target.status != 200) {
- return;
- }
-
- /* Update the the last check time */
- wot_prefs.setChar("update_checked", Date.now().toString());
-
- var update = null;
- var tags =
- event.target.responseXML.getElementsByTagName(WOT_PLATFORM);
-
- if (tags) {
- update = tags.item(0);
- }
-
- if (!update) {
- return;
- }
-
- /* Version */
- var version = null;
-
- if (update.attributes) {
- version = update.attributes.getNamedItem(
- WOT_SERVICE_XML_UPDATE_VERSION);
- }
-
- if (version && version.nodeValue) {
- wot_prefs.setChar("update_version", version.nodeValue);
- wot_core.update();
- }
-
- /* Search rules */
- var search = event.target.responseXML.getElementsByTagName(
- WOT_SERVICE_XML_UPDATE_SEARCH);
-
- if (search) {
- wot_search.parse(search);
- }
- } catch (e) {
- dump("wot_api_update.onload: failed with " + e + "\n");
- }
- }
- };
-
- wot_api_update.init();
-